package com.itheima.area.controller;

import com.itheima.area.pojo.CustFarmlandDevice;
import com.itheima.area.service.DeviceService;
import com.itheima.crops.feign.IndexFeign;
import com.itheima.entity.Result;
import com.itheima.entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
 * @PackageName com.itheima.area.controller
 * @ProjectName Ceres-Work
 * @Created by Chanly on 2020/10/15 20:52
 **/
@RestController
@RequestMapping("/device")
public class DevController {
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private IndexFeign indexFeign;
    @GetMapping
    public Result findAll() {
        try {
            List<CustFarmlandDevice> custFarmlandDeviceList = deviceService.findAll();
            return new Result(true, StatusCode.OK, "查询成功",custFarmlandDeviceList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,StatusCode.ERROR,"查询设备失败");
        }
    }
    @GetMapping("/index/{id}")
    public Result findIndex(@PathVariable Integer id){
      try {
          Result result = indexFeign.findById(id);
          return new Result(true,StatusCode.OK,"查询成功",result);
      } catch (Exception e) {
          e.printStackTrace();
          return new Result(false,StatusCode.ERROR,"查询失败");
      }
  }
}
